package com.vooda.business_admin.controller.sys;


import com.vooda.business_admin.common.ReqDataTableDto;
import com.vooda.business_admin.common.RspDataTableDto;
import com.vooda.business_admin.entity.SysUser;
import com.vooda.business_admin.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping(value = "/management")
public class SysUserController {

    @Autowired
    SysUserService sysUserService;


    @GetMapping("/managerList")
    public RspDataTableDto<SysUser> findManagerList(ReqDataTableDto reqDataTableDTO) {
        return sysUserService.findManagerList(reqDataTableDTO);
    }

    @PostMapping("/saveManager")
    public void saveManager(SysUser sysUser) {
        sysUserService.saveManager(sysUser);
    }

    @GetMapping("/removeManager/{id}")
    public void removeManager(@PathVariable Long id) {
        sysUserService.deleteByPrimaryKey(id);
    }

    @GetMapping("/isManagerExist")
    public Boolean checkManagerExists(String account) {
        return sysUserService.findByUserName(account)!=null?false:true;
    }

    @GetMapping("/resetPassword/{id}")
    public void resetPassword(@PathVariable Long id) {
        sysUserService.resetPassword(id);
    }

    @PostMapping("/updatePassword")
    public void updatePassword(HttpServletRequest request, String password) {
        sysUserService.updatePassword((Long)request.getSession().getAttribute("currentUserId"),password);
    }

    @PostMapping("/checkPassword")
    public Boolean checkPassword(String oldPwd,HttpServletRequest request) {
       return sysUserService.checkPassword((Long)request.getSession().getAttribute("currentUserId"),oldPwd);
    }
}
